package org.vestbjergbyggecenter.Controller;

import java.util.ArrayList;

import org.vestbjergbyggecenter.Model.CategoryRecords;
import org.vestbjergbyggecenter.Model.Customer;
import org.vestbjergbyggecenter.Model.CustomerRecords;

public class CustomerCtr {
	private CustomerRecords customers;
	private CategoryRecords categories;
    private static CustomerCtr instance = null;
    
    private CustomerCtr()
    {
            customers = CustomerRecords.getInstance();
            categories = CategoryRecords.getInstance();
    }
    
    public static CustomerCtr getInstance()
    {     
          instance=new CustomerCtr();
            
            return instance;
    }
    
    public void createCustomer(int customerID, String customerName, long customerCPR, String customerAddress, long customerPostalCode, String customerCity, String customerPhone, 
			String customerCategory)
    {
            Customer newCustomer = new Customer(customerID, customerName, customerCPR, customerAddress, 
            		customerPostalCode, customerCity, customerPhone, categories.getCategoryByTitle(customerCategory));
            customers.addCustomer(newCustomer);
    }
    
    public Customer getCustomer(int id)
    {
        Customer customer = customers.getCustomer(id);
        return customer;
    }
    
    public ArrayList<Customer> getCustomers()
    {
            return customers.getCustomers();
    }
    
    public void updateCustomer(int id, String name, long CPR, String address, long postalCode, String city, String phone, String category)
    {
        Customer customer = getCustomer(id);
        customer.setName(name);
        customer.setAddress(address);
        customer.setCPR(CPR);
        customer.setCity(city);
        customer.setPostalCode(postalCode);
        customer.setPhone(phone);
        customer.setCategory(categories.getCategoryByTitle(category));
    }
    
    public void deleteCustomer(int id)
    {
            if(getCustomer(id)==null)
            {
                System.out.println("Please enter a valid customers ID");
            }
            else
            {
            	customers.removeCustomer(id);
            }
    }    
    
    public void printCustomer(int id)
    {
            Customer customer = getCustomer(id);
            if(customer != null)
            {
            	customer.printCustomer();
            }
            else
            {
            	System.out.println("Please insert a valid customer ID.");
            } 
    }
    
    public void printCustomers()
    {
            customers.printCustomers();
    }
    
    public void printMonthBill(int id)
    {
    	Customer customer = customers.getCustomer(id);
    	if(customer!=null)
    	{
    		customer.printCustomerMonthBill();    
    	}
    	else
    	{
    		System.out.println("Please insert a valid customer ID.");	
    	}   	
    }
}
